#ifndef TOOL_H
#define TOOL_H


#include "kcfjsonhandle.h"
#include "kinitializationsettings.h"
#include <QObject>
#include "ktcpconnection.h"
#include <QFileInfoList>
class Tool : public QObject {
    Q_OBJECT
public:
    Tool(QObject *parent = nullptr);
    static Tool* getStaticTool();
    QByteArray getKCFDirLocation() const;
    void setKCFDirLocation(const QByteArray &newKCFDirLocation);
    void KCFanalysis();
    Q_INVOKABLE void handleQVariantToFile(QVariant variant);
    QJsonObject QVariantMapToQJsonObject(QVariantMap qvariantmap);
    Q_INVOKABLE void toolWriteToLogin(QByteArray acc,QByteArray psw,bool);
    void connectToServer();






    QString getVip() const;
    void setVip(const QString &newVip);
    void resetVip();

    QString getId() const;
    void setId(const QString &newId);
    void resetId();

    QString getName() const;
    void setName(const QString &newName);
    void resetName();
    void checkAndCreateUserFile();
    void checkToLoginAuto();


    QString getIsVip() const;
    void setIsVip(const QString &newIsVip);
    void resetIsVip();

    bool getIsLogined() const;
    void setIsLogined(bool newIsLogined);
    void resetIsLogined();

    bool getIsToSaveToLocation() const;
    void setIsToSaveToLocation(bool newIsToSaveToLocation);
    void createAutoLoginFile(QString acc, QString psw);
    QString getTmpAcc() const;
    void setTmpAcc(const QString &newTmpAcc);

    QString getTmpPsw() const;
    void setTmpPsw(const QString &newTmpPsw);
    Q_INVOKABLE void readFileOpenInfo(QByteArray);
    Q_INVOKABLE void writeFileOpenInfo(QByteArray);
signals:


    Q_INVOKABLE void sendFileOpenInfo(QByteArray,QByteArray);
    Q_INVOKABLE void loginSuc();
    void joctoqml(QVariant jsonObj);
    void isVipChanged();

    void vipChanged();

    void idChanged();

    void nameChanged();

    void isLoginedChanged();

private:
    QString tmpAcc;
    QString tmpPsw;
    bool isToSaveToLocation=false;
    Q_INVOKABLE bool isLogined=false;
    Q_INVOKABLE QString isVip;
    Q_INVOKABLE QString vip;
    Q_INVOKABLE QString id;
    Q_INVOKABLE QString name;

    static Tool* staticTool;
    QByteArray KCFDirLocation;
    KInitializationSettings KIS;
    KCFJsonHandle KCFJH;
    QString ip="127.0.0.1";
    int port=10999;
    KTcpConnection *clientToServer;

    QString userDIr="./account";


    Q_PROPERTY(QString vip READ getVip WRITE setVip RESET resetVip NOTIFY vipChanged FINAL)
    Q_PROPERTY(QString id READ getId WRITE setId RESET resetId NOTIFY idChanged FINAL)
    Q_PROPERTY(QString name READ getName WRITE setName RESET resetName NOTIFY nameChanged FINAL)
    Q_PROPERTY(QString isVip READ getIsVip WRITE setIsVip RESET resetIsVip NOTIFY isVipChanged FINAL)
    Q_PROPERTY(bool isLogined READ getIsLogined WRITE setIsLogined RESET resetIsLogined NOTIFY isLoginedChanged FINAL)
};

#endif // TOOL_H
